import 'package:full_flutter/utils/string_utils.dart';

class Article {
  late String? apkLink;
  late String author;

  /// 2019.10.13 添加分享人,author可能为空
  late String? shareUser;
  late int chapterId;
  late String chapterName;
  bool collect = false;
  late int courseId;
  late String desc;
  late String envelopePic;
  bool fresh = false;
  late int id;
  late String link;
  late String niceDate;
  late String origin;
  int? originId;
  late String? prefix;
  late String? projectLink;
  late int publishTime;
  late int? superChapterId;
  String? superChapterName;
  late List<TagsBean?>? tags;
  late String title;
  int? type;
  late int userId;
  late int visible;
  late int zan;

  static Article fromMap(Map<String, dynamic> map) {
    Article articleBean = Article();
    articleBean.apkLink = map['apkLink'];
    articleBean.author = map['author'];
    articleBean.shareUser = map['shareUser'];
    articleBean.chapterId = map['chapterId'];
//    articleBean.chapterName = map['chapterName'];
    articleBean.chapterName = StringUtils.urlDecoder(map["chapterName"]);
    articleBean.collect = map['collect'] ?? false;
    articleBean.courseId = map['courseId'];
//    articleBean.desc = map['desc'];
    articleBean.desc = StringUtils.urlDecoder(map["desc"]);
    articleBean.envelopePic = map['envelopePic'];
    articleBean.fresh = map['fresh'] ?? false;
    articleBean.id = map['id'];
    articleBean.link = map['link'];
    articleBean.niceDate = map['niceDate'];
    articleBean.origin = map['origin'];
    articleBean.originId = map['originId'];
    articleBean.prefix = map['prefix'];
    articleBean.projectLink = map['projectLink'];
    articleBean.publishTime = map['publishTime'];
    articleBean.superChapterId = map['superChapterId'];
//    articleBean.superChapterName = map['superChapterName'];
    articleBean.superChapterName =
        StringUtils.urlDecoder(map["superChapterName"] ?? '');
    articleBean.tags = [];
    // ..addAll((map['tags'] ?? []).map((o) => TagsBean.fromMap(o)).toList());
    articleBean.title = StringUtils.urlDecoder(map["title"]);
    articleBean.type = map['type'];
    articleBean.userId = map['userId'];
    articleBean.visible = map['visible'];
    articleBean.zan = map['zan'];
    return articleBean;
  }

  Map toJson() => {
        "apkLink": apkLink,
        "author": author,
        "shareUser": shareUser,
        "chapterId": chapterId,
        "chapterName": chapterName,
        "collect": collect,
        "courseId": courseId,
        "desc": desc,
        "envelopePic": envelopePic,
        "fresh": fresh,
        "id": id,
        "link": link,
        "niceDate": niceDate,
        "origin": origin,
        "originId": originId,
        "prefix": prefix,
        "projectLink": projectLink,
        "publishTime": publishTime,
        "superChapterId": superChapterId,
        "superChapterName": superChapterName,
        "tags": tags,
        "title": title,
        "type": type,
        "userId": userId,
        "visible": visible,
        "zan": zan,
      };
}

class TagsBean {
  late String name;
  late String url;

  static TagsBean? fromMap(Map<String, dynamic>? map) {
    if (map == null) return null;
    TagsBean tagsBean = TagsBean();
    tagsBean.name = map['name'];
    tagsBean.url = map['url'];
    return tagsBean;
  }

  Map toJson() => {
        "name": name,
        "url": url,
      };
}
